package net.entelijan.cobean.examples.showcase.multisel;

import static org.junit.Assert.assertArrayEquals;

import java.util.List;

import net.entelijan.cobean.core.ColumnDesc;
import net.entelijan.cobean.core.IMultiSelectionListCobean;
import net.entelijan.cobean.examples.showcase.ShowcaseTestFrame;
import net.entelijan.cobean.examples.util.Locale;
import net.entelijan.cobean.examples.util.ExamplesUtil;
import net.entelijan.cobean.multisel.DefaultMultiselInitializer;
import net.entelijan.cobean.util.CobeanUtil;

import org.fest.swing.fixture.FrameFixture;
import org.fest.swing.fixture.JButtonFixture;
import org.fest.swing.fixture.JListFixture;
import org.junit.Test;

@SuppressWarnings("unused")
public class OrderMultiselFestTestCase {

	@Test
	public void test() {
		OrderMultiselPanel panel = new OrderMultiselPanel();
		ShowcaseTestFrame frame = new ShowcaseTestFrame(panel);
		FrameFixture showcaseFix = new FrameFixture(frame);
		try {
			showcaseFix.show();

			DefaultMultiselInitializer<Locale> ini = new DefaultMultiselInitializer<Locale>();
			ini.setCoAddButton(panel.getMultiselPanel().getAddButton());
			ini.setCoRemoveButton(panel.getMultiselPanel().getRemoveButton());
			ini.setCoLeftList(panel.getMultiselPanel().getLeftList());
			ini.setCoRightList(panel.getMultiselPanel().getRightList());
			List<ColumnDesc> colDescs = ColumnDesc
					.createPropertyOnlyColumnDescs("ISO3Country",
							"ISO3Language", "displayCountry", "displayLanguage");
			ini.setColumnDescs(colDescs);
			final IMultiSelectionListCobean<Locale> cobean = ini.initialize();
			final List<Locale> data = ExamplesUtil.createLocales();
			cobean.setValue(data);
			cobean.setSelectedValue(CobeanUtil.createListWithOneEntry(data
					.get(3)));

			JListFixture leftList = showcaseFix
					.list("DefaultMultiselPanel.leftList");
			JListFixture rightList = showcaseFix
					.list("DefaultMultiselPanel.rightList");
			JButtonFixture addButton = showcaseFix
					.button("DefaultMultiselPanel.addButton");
			// TODO Make some tests with the remove button
			// JButtonFixture removeButton = showcaseFix.button("DefaultMultiselPanel.removeButton");
			// Assert initial data
			{
				leftList.requireNoSelection();
				rightList.requireNoSelection();
				assertArrayEquals(getInitialLeftList(), leftList.contents());
				assertArrayEquals(getInitialRightList(), rightList.contents());
			}
			// Select one
			{
				leftList.selectItem(5);
				addButton.click();
				pauseShort();
				assertArrayEquals(getLeftList01(), leftList.contents());
				assertArrayEquals(getRightList01(), rightList.contents());
			}
			// Select first
			{
				leftList.selectItem(0);
				addButton.click();
				pauseShort();
				leftList.requireNoSelection();
				rightList.requireSelection("jpn jpn Japan Japanese");
				assertArrayEquals(getLeftList02(), leftList.contents());
				assertArrayEquals(getRightList02(), rightList.contents());
			}
		} finally {
			pauseShort();
			showcaseFix.cleanUp();
		}
	}

	private String[] getInitialRightList() {
		return new String[] { "spa spa Panama Spanish" };
	}

	private String[] getInitialLeftList() {
		return new String[] { "jpn jpn Japan Japanese", "spa spa Peru Spanish",
				"jpn jpn Japan Japanese",
				"srp srp Bosnia and Herzegovina Serbian",
				"spa spa Guatemala Spanish",
				"ara ara United Arab Emirates Arabic",
				"nor nor Norway Norwegian", "sqi sqi Albania Albanian",
				"ara ara Iraq Arabic", "ara ara Yemen Arabic",
				"por por Portugal Portuguese", "ell ell Cyprus Greek",
				"ara ara Qatar Arabic", "mkd mkd Macedonia Macedonian",
				"deu deu Switzerland German", "eng eng United States English",
				"fin fin Finland Finnish", "eng eng Malta English",
				"slv slv Slovenia Slovenian", "slk slk Slovakia Slovak",
				"tur tur Turkey Turkish", "ara ara Saudi Arabia Arabic",
				"eng eng United Kingdom English",
				"srp srp Serbia and Montenegro Serbian",
				"eng eng New Zealand English", "nor nor Norway Norwegian",
				"lit lit Lithuania Lithuanian", "spa spa Nicaragua Spanish",
				"gle gle Ireland Irish", "fra fra Belgium French",
				"spa spa Spain Spanish", "ara ara Lebanon Arabic",
				"fra fra Canada French", "est est Estonia Estonian",
				"ara ara Kuwait Arabic", "srp srp Serbia Serbian",
				"spa spa United States Spanish", "spa spa Mexico Spanish",
				"ara ara Sudan Arabic", "ind ind Indonesia Indonesian",
				"spa spa Uruguay Spanish", "lav lav Latvia Latvian",
				"por por Brazil Portuguese", "ara ara Syria Arabic",
				"spa spa Dominican Republic Spanish",
				"fra fra Switzerland French", "hin hin India Hindi",
				"spa spa Venezuela Spanish", "ara ara Bahrain Arabic",
				"eng eng Philippines English", "ara ara Tunisia Arabic",
				"deu deu Austria German", "nld nld Netherlands Dutch",
				"spa spa Ecuador Spanish", "zho zho Taiwan Chinese",
				"ara ara Jordan Arabic", "isl isl Iceland Icelandic",
				"spa spa Colombia Spanish", "spa spa Costa Rica Spanish",
				"spa spa Chile Spanish", "ara ara Egypt Arabic",
				"eng eng South Africa English", "tha tha Thailand Thai",
				"ell ell Greece Greek", "ita ita Italy Italian",
				"hun hun Hungary Hungarian", "eng eng Ireland English",
				"ukr ukr Ukraine Ukrainian", "pol pol Poland Polish",
				"fra fra Luxembourg French", "nld nld Belgium Dutch",
				"eng eng India English", "cat cat Spain Catalan",
				"ara ara Morocco Arabic", "spa spa Bolivia Spanish",
				"eng eng Australia English", "zho zho Singapore Chinese",
				"spa spa El Salvador Spanish", "rus rus Russia Russian",
				"kor kor South Korea Korean", "ara ara Algeria Arabic",
				"vie vie Vietnam Vietnamese", "srp srp Montenegro Serbian",
				"ara ara Libya Arabic", "zho zho China Chinese",
				"bel bel Belarus Belarusian", "zho zho Hong Kong Chinese",
				"heb heb Israel Hebrew", "bul bul Bulgaria Bulgarian",
				"mlt mlt Malta Maltese", "spa spa Paraguay Spanish",
				"fra fra France French", "ces ces Czech Republic Czech",
				"ita ita Switzerland Italian", "ron ron Romania Romanian",
				"spa spa Puerto Rico Spanish", "eng eng Canada English",
				"deu deu Germany German", "deu deu Luxembourg German",
				"spa spa Argentina Spanish", "msa msa Malaysia Malay",
				"hrv hrv Croatia Croatian", "eng eng Singapore English",
				"ara ara Oman Arabic", "tha tha Thailand Thai",
				"swe swe Sweden Swedish", "dan dan Denmark Danish",
				"spa spa Honduras Spanish"

		};
	}

	private String[] getRightList01() {
		return new String[] { "spa spa Panama Spanish",
				"ara ara United Arab Emirates Arabic" };
	}

	private String[] getLeftList01() {
		return new String[] { "jpn jpn Japan Japanese", "spa spa Peru Spanish",
				"jpn jpn Japan Japanese",
				"srp srp Bosnia and Herzegovina Serbian",
				"spa spa Guatemala Spanish", "nor nor Norway Norwegian",
				"sqi sqi Albania Albanian", "ara ara Iraq Arabic",
				"ara ara Yemen Arabic", "por por Portugal Portuguese",
				"ell ell Cyprus Greek", "ara ara Qatar Arabic",
				"mkd mkd Macedonia Macedonian", "deu deu Switzerland German",
				"eng eng United States English", "fin fin Finland Finnish",
				"eng eng Malta English", "slv slv Slovenia Slovenian",
				"slk slk Slovakia Slovak", "tur tur Turkey Turkish",
				"ara ara Saudi Arabia Arabic",
				"eng eng United Kingdom English",
				"srp srp Serbia and Montenegro Serbian",
				"eng eng New Zealand English", "nor nor Norway Norwegian",
				"lit lit Lithuania Lithuanian", "spa spa Nicaragua Spanish",
				"gle gle Ireland Irish", "fra fra Belgium French",
				"spa spa Spain Spanish", "ara ara Lebanon Arabic",
				"fra fra Canada French", "est est Estonia Estonian",
				"ara ara Kuwait Arabic", "srp srp Serbia Serbian",
				"spa spa United States Spanish", "spa spa Mexico Spanish",
				"ara ara Sudan Arabic", "ind ind Indonesia Indonesian",
				"spa spa Uruguay Spanish", "lav lav Latvia Latvian",
				"por por Brazil Portuguese", "ara ara Syria Arabic",
				"spa spa Dominican Republic Spanish",
				"fra fra Switzerland French", "hin hin India Hindi",
				"spa spa Venezuela Spanish", "ara ara Bahrain Arabic",
				"eng eng Philippines English", "ara ara Tunisia Arabic",
				"deu deu Austria German", "nld nld Netherlands Dutch",
				"spa spa Ecuador Spanish", "zho zho Taiwan Chinese",
				"ara ara Jordan Arabic", "isl isl Iceland Icelandic",
				"spa spa Colombia Spanish", "spa spa Costa Rica Spanish",
				"spa spa Chile Spanish", "ara ara Egypt Arabic",
				"eng eng South Africa English", "tha tha Thailand Thai",
				"ell ell Greece Greek", "ita ita Italy Italian",
				"hun hun Hungary Hungarian", "eng eng Ireland English",
				"ukr ukr Ukraine Ukrainian", "pol pol Poland Polish",
				"fra fra Luxembourg French", "nld nld Belgium Dutch",
				"eng eng India English", "cat cat Spain Catalan",
				"ara ara Morocco Arabic", "spa spa Bolivia Spanish",
				"eng eng Australia English", "zho zho Singapore Chinese",
				"spa spa El Salvador Spanish", "rus rus Russia Russian",
				"kor kor South Korea Korean", "ara ara Algeria Arabic",
				"vie vie Vietnam Vietnamese", "srp srp Montenegro Serbian",
				"ara ara Libya Arabic", "zho zho China Chinese",
				"bel bel Belarus Belarusian", "zho zho Hong Kong Chinese",
				"heb heb Israel Hebrew", "bul bul Bulgaria Bulgarian",
				"mlt mlt Malta Maltese", "spa spa Paraguay Spanish",
				"fra fra France French", "ces ces Czech Republic Czech",
				"ita ita Switzerland Italian", "ron ron Romania Romanian",
				"spa spa Puerto Rico Spanish", "eng eng Canada English",
				"deu deu Germany German", "deu deu Luxembourg German",
				"spa spa Argentina Spanish", "msa msa Malaysia Malay",
				"hrv hrv Croatia Croatian", "eng eng Singapore English",
				"ara ara Oman Arabic", "tha tha Thailand Thai",
				"swe swe Sweden Swedish", "dan dan Denmark Danish",
				"spa spa Honduras Spanish" };
	}

	private String[] getRightList02() {
		return new String[] { "spa spa Panama Spanish",
				"ara ara United Arab Emirates Arabic", "jpn jpn Japan Japanese" };
	}

	private String[] getLeftList02() {
		return new String[] { "spa spa Peru Spanish", "jpn jpn Japan Japanese",
				"srp srp Bosnia and Herzegovina Serbian",
				"spa spa Guatemala Spanish", "nor nor Norway Norwegian",
				"sqi sqi Albania Albanian", "ara ara Iraq Arabic",
				"ara ara Yemen Arabic", "por por Portugal Portuguese",
				"ell ell Cyprus Greek", "ara ara Qatar Arabic",
				"mkd mkd Macedonia Macedonian", "deu deu Switzerland German",
				"eng eng United States English", "fin fin Finland Finnish",
				"eng eng Malta English", "slv slv Slovenia Slovenian",
				"slk slk Slovakia Slovak", "tur tur Turkey Turkish",
				"ara ara Saudi Arabia Arabic",
				"eng eng United Kingdom English",
				"srp srp Serbia and Montenegro Serbian",
				"eng eng New Zealand English", "nor nor Norway Norwegian",
				"lit lit Lithuania Lithuanian", "spa spa Nicaragua Spanish",
				"gle gle Ireland Irish", "fra fra Belgium French",
				"spa spa Spain Spanish", "ara ara Lebanon Arabic",
				"fra fra Canada French", "est est Estonia Estonian",
				"ara ara Kuwait Arabic", "srp srp Serbia Serbian",
				"spa spa United States Spanish", "spa spa Mexico Spanish",
				"ara ara Sudan Arabic", "ind ind Indonesia Indonesian",
				"spa spa Uruguay Spanish", "lav lav Latvia Latvian",
				"por por Brazil Portuguese", "ara ara Syria Arabic",
				"spa spa Dominican Republic Spanish",
				"fra fra Switzerland French", "hin hin India Hindi",
				"spa spa Venezuela Spanish", "ara ara Bahrain Arabic",
				"eng eng Philippines English", "ara ara Tunisia Arabic",
				"deu deu Austria German", "nld nld Netherlands Dutch",
				"spa spa Ecuador Spanish", "zho zho Taiwan Chinese",
				"ara ara Jordan Arabic", "isl isl Iceland Icelandic",
				"spa spa Colombia Spanish", "spa spa Costa Rica Spanish",
				"spa spa Chile Spanish", "ara ara Egypt Arabic",
				"eng eng South Africa English", "tha tha Thailand Thai",
				"ell ell Greece Greek", "ita ita Italy Italian",
				"hun hun Hungary Hungarian", "eng eng Ireland English",
				"ukr ukr Ukraine Ukrainian", "pol pol Poland Polish",
				"fra fra Luxembourg French", "nld nld Belgium Dutch",
				"eng eng India English", "cat cat Spain Catalan",
				"ara ara Morocco Arabic", "spa spa Bolivia Spanish",
				"eng eng Australia English", "zho zho Singapore Chinese",
				"spa spa El Salvador Spanish", "rus rus Russia Russian",
				"kor kor South Korea Korean", "ara ara Algeria Arabic",
				"vie vie Vietnam Vietnamese", "srp srp Montenegro Serbian",
				"ara ara Libya Arabic", "zho zho China Chinese",
				"bel bel Belarus Belarusian", "zho zho Hong Kong Chinese",
				"heb heb Israel Hebrew", "bul bul Bulgaria Bulgarian",
				"mlt mlt Malta Maltese", "spa spa Paraguay Spanish",
				"fra fra France French", "ces ces Czech Republic Czech",
				"ita ita Switzerland Italian", "ron ron Romania Romanian",
				"spa spa Puerto Rico Spanish", "eng eng Canada English",
				"deu deu Germany German", "deu deu Luxembourg German",
				"spa spa Argentina Spanish", "msa msa Malaysia Malay",
				"hrv hrv Croatia Croatian", "eng eng Singapore English",
				"ara ara Oman Arabic", "tha tha Thailand Thai",
				"swe swe Sweden Swedish", "dan dan Denmark Danish",
				"spa spa Honduras Spanish" };
	}

	private synchronized void pauseShort() {
		try {
			wait(200);
		} catch (InterruptedException ex) {
			// Dont worry about that exception
		}
	}

	private synchronized void pauseMedium() {
		try {
			wait(1000);
		} catch (InterruptedException ex) {
			// Dont worry about that exception
		}
	}

	private synchronized void pauseLong() {
		try {
			wait(4000);
		} catch (InterruptedException ex) {
			// Dont worry about that exception
		}
	}

}
